<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui"
	template="/pages/template/layoutAdmin.xhtml">

<ui:define name="body">

	<h:form prependId="false" id="form">
	
		<h:panelGroup layout="block" id="cadastro">
		
			<h:panelGroup layout="block" id="txtInformativoPagina">
				<h:outputText value="#{msg['label.cadastro.servico.especialidade']}" />
			</h:panelGroup>
			
			<h:panelGroup layout="block" styleClass="painelEsquerdo">
			
				<h:panelGroup layout="block" styleClass="divLabelForm">
					<h:outputLabel value="#{msg['label.servico']}"></h:outputLabel>
				</h:panelGroup>
				<h:panelGroup layout="block" styleClass="divInputAddForm">
					<p:autoComplete value="#{servicoAction.selectedServicoField}" completeMethod="#{servicoAction.completeServicos}" var="servico" 
						itemLabel="#{servico.nome}" itemValue="#{servico}" multiple="false" converter="#{tipoServicoConverter}" size="40">
							<p:column>
								#{servico.nome}
							</p:column>
					</p:autoComplete>
				</h:panelGroup>
				<h:panelGroup layout="block" styleClass="divInputAddForm">
					<p:spacer width="10" />
					<p:commandLink ajax="true" actionListener="#{servicoAction.addServico}" update=":msgSistemaGeral panelTree">
						<h:graphicImage value="/img/btn_add.png" />
					</p:commandLink>
				</h:panelGroup>
				
			</h:panelGroup>
			
			<h:panelGroup layout="block" styleClass="painelDireito">
			
				<h:panelGroup layout="block" styleClass="divLabelForm">
					<h:outputLabel value="#{msg['label.especialidade']}"></h:outputLabel>
				</h:panelGroup>
				<h:panelGroup layout="block" styleClass="divInputAddForm">
					<p:autoComplete value="#{servicoAction.selectedEspecialidade}" completeMethod="#{servicoAction.completeEspecialidades}" var="espec" 
						itemLabel="#{espec.nome}" itemValue="#{espec}" multiple="false" converter="#{especialidadeConverter}" size="40">
							<p:column>
								#{espec.nome}
							</p:column>
					</p:autoComplete>
				</h:panelGroup>
				<h:panelGroup layout="block" styleClass="divInputAddForm">
					<p:spacer width="10" />
					<p:commandLink ajax="true" actionListener="#{servicoAction.addEspecialidade}" update="panelTree">
						<h:graphicImage value="/img/btn_add.png" />
					</p:commandLink>
				</h:panelGroup>
				
			</h:panelGroup>
			
			<h:panelGroup layout="block" styleClass="clearAll">
				<p:spacer height="20" />
			</h:panelGroup>
			
			<h:panelGroup layout="block" id="panelTree" styleClass="painel" style="margin-left: 0% !important;">
				<div style="width: 50%; margin: 0 auto;">
			
					<p:tree value="#{servicoAction.root}" var="node" selectionMode="single"
						orientation="horizontal" selection="#{servicoAction.selectedNode}">
						
						<p:ajax event="select" listener="#{servicoAction.onDeleteNode}" oncomplete="wdgPanelConfirmaExclusao.show();" update=":form:panelConfirmaExclusao"/>
						
						<p:treeNode>
							<h:outputText value="#{node}" />
						</p:treeNode>
					
					</p:tree>
					
				</div>			
			</h:panelGroup>
			
			<h:panelGroup layout="block" styleClass="clearAll">
				<p:spacer height="20" />
			</h:panelGroup>
			
			<h:panelGroup layout="block" id="panelServicos" styleClass="painel" style="margin-left: 0% !important;">
				<div style="width: 50%; margin: 0 auto;">
			
				<p:dataTable id="tbServicos" var="servico" value="#{servicoAction.tipoServicoDataModel}" paginator="true" rows="10" paginatorPosition="bottom"
					selection="#{servicoAction.selectedServicoTable}" selectionMode="single" currentPageReportTemplate="({currentPage} de {totalPages})"
					paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
					emptyMessage="#{msg['no.records.found']}">
					
					<p:ajax event="rowSelect" listener="#{servicoAction.onRowSelect}" update=":msgSistemaGeral :form:panelTree" />
					
					<f:facet name="header">
						<h:outputText value="#{msg['label.servicos']}" />
					</f:facet>
					
					<p:column>
						<h:outputText value="#{servico.nome}" />
					</p:column>
				
				</p:dataTable>
								
				</div>
			</h:panelGroup>
			
			<p:dialog id="panelConfirmaExclusao" resizable="false" width="410" height="140" widgetVar="wdgPanelConfirmaExclusao" closable="false">
				<h:panelGroup layout="block">
					<h:panelGroup layout="block" id="panelEditServico" rendered="#{servicoAction.deleteEspecialidade == null}">
						<h:panelGroup layout="block" styleClass="divLabelForm" style="text-align:center;">
							<h:outputText value="#{msg['label.servico']}" />
						</h:panelGroup>
						<h:panelGroup layout="block" styleClass="divInputAddForm">
							<p:inputText value="#{servicoAction.editServico}" size="40"/>
						</h:panelGroup>
						<h:panelGroup layout="block" styleClass="divInputAddForm">
							<p:spacer width="10" />
							<p:commandLink ajax="true" actionListener="#{servicoAction.deleteNode}" update=":msgSistemaGeral panelTree">
								<h:graphicImage value="/img/btn_remove.png" />
							</p:commandLink>
						</h:panelGroup>
					</h:panelGroup>
					<h:panelGroup layout="block" id="panelEditEspecialidade" rendered="#{servicoAction.deleteEspecialidade != null}">
						<h:panelGroup layout="block" styleClass="divLabelForm" style="text-align:center;">
							<h:outputText value="#{msg['label.especialidade']}" />
						</h:panelGroup>
						<h:panelGroup layout="block" styleClass="divInputAddForm">
							<p:inputText value="#{servicoAction.deleteEspecialidade.nome}" size="40" />
						</h:panelGroup>
						<h:panelGroup layout="block" styleClass="divInputAddForm">
							<p:spacer width="10" />
							<p:commandLink ajax="true" actionListener="#{servicoAction.deleteNode}" update=":msgSistemaGeral :form:cadastro">
								<h:graphicImage value="/img/btn_remove.png" />
							</p:commandLink>
						</h:panelGroup>
					</h:panelGroup>
					<h:panelGroup layout="block" styleClass="buttonFormBar">
						<h:panelGroup layout="block" styleClass="divInputForm">
							<p:commandLink ajax="true" actionListener="#{servicoAction.alterar}" update=":msgSistemaGeral :form:cadastro">
								<h:graphicImage value="/img/btn_cadastrar.png" />
							</p:commandLink>
							<p:spacer width="10" />
							<p:commandLink oncomplete="wdgPanelConfirmaExclusao.hide();">
								<h:graphicImage value="/img/btn_fechar.png" />
							</p:commandLink>
						</h:panelGroup>
					</h:panelGroup>
				</h:panelGroup>
			</p:dialog>
			
			<h:panelGroup layout="block" styleClass="buttonFormBar">
				<h:panelGroup layout="block" styleClass="divInputForm">
					<p:commandLink ajax="true" actionListener="#{servicoAction.salvar}" immediate="true" update=":msgSistemaGeral cadastro">
						<h:graphicImage value="/img/btn_cadastrar.png" />
					</p:commandLink>
					<p:spacer width="10" />
					<p:commandLink ajax="true" actionListener="#{servicoAction.limpar}" update=":msgSistemaGeral cadastro">
						<h:graphicImage value="/img/btn_limpar.png" />
					</p:commandLink>
				</h:panelGroup>
			</h:panelGroup>
		
		</h:panelGroup>
	
	</h:form>
	
</ui:define>
</ui:composition>